#include "VideoFrameQueue.h"
#include <algorithm>

VideoFrameQueue::VideoFrameQueue(double fps, double maxCapacity)
    :FrameQueue(), m_fps(fps), m_maxCapacity(maxCapacity)
{
	
}

bool VideoFrameQueue::isFull()
{
	std::lock_guard<std::mutex>	lock(m_m);
    return m_q.size() >= 5;

	double duration = m_q.size() / m_fps;
    return m_maxCapacity < duration;
}

void VideoFrameQueue::onFramePushed(AVFrame *frame)
{
    std::lock_guard<std::mutex>	lock(m_m);
    if (m_q.size() == 1) {
        m_firstPTS = m_q.front()->pts;
    }
}

void VideoFrameQueue::onFramePoped(AVFrame *frmae)
{
    std::lock_guard<std::mutex>	lock(m_m);
    if (!m_q.empty()) {
        m_firstPTS = m_q.front()->pts;
    }
}
